%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Appendix Figure A.2:
frequencies = csvread('dsets_for_model\data_for_histograms_sec2.csv',1,0);
frequencies = frequencies(1:N,2:end);
figure
subplot(3,3,1), hist(frequencies(:,1)), title('Human Necessities')
subplot(3,3,1), ylabel('Frequency')
subplot(3,3,2), hist(frequencies(:,2)), title('Transportation')
subplot(3,3,3), hist(frequencies(:,3)), title('Chemistry')
subplot(3,3,4), hist(frequencies(:,4)), title('Construction')
subplot(3,3,4), ylabel('Frequency')
subplot(3,3,5), hist(frequencies(:,5)), title('Mech. Eng.')
subplot(3,3,6), hist(frequencies(:,6)), title('Physics')
subplot(3,3,8), hist(frequencies(:,7)), title('Electricity')
subplot(3,3,8), ylabel('Frequency')

frequencies = csvread('dsets_for_model\data_for_histograms_sec2.csv',1,0);
frequencies = frequencies(N+1:end,2:end);
figure
subplot(3,3,1), hist(frequencies(:,1)), title('Human Necessities')
subplot(3,3,1), ylabel('Frequency')
subplot(3,3,2), hist(frequencies(:,2)), title('Transportation')
subplot(3,3,3), hist(frequencies(:,3)), title('Chemistry')
subplot(3,3,4), hist(frequencies(:,4)), title('Construction')
subplot(3,3,4), ylabel('Frequency')
subplot(3,3,5), hist(frequencies(:,5)), title('Mech. Eng.')
subplot(3,3,6), hist(frequencies(:,6)), title('Physics')
subplot(3,3,8), hist(frequencies(:,7)), title('Electricity')
subplot(3,3,8), ylabel('Frequency')

%%% Appendix Figure A.3:
binscatter_points = csvread('dsets_for_model\fact_1.csv',1,0);
figure
scatter(binscatter_points(:,1),binscatter_points(:,2),'b','o',...
    'MarkerEdgeColor','b','MarkerFaceColor','b','DisplayName','Data')
hold on
plot(binscatter_points(:,1),.2794997+.4640188*binscatter_points(:,1),'b','HandleVisibility','off')
xlabel('Exposure to technological wave')
ylabel('20-year population growth')

%%% Appendix Figure A.4:
binscatter_points = csvread('dsets_for_model\data_for_scatter_exposure_industry.csv',1,0);
figure
scatter(binscatter_points(:,5),binscatter_points(:,4),50000*binscatter_points(:,3),'b','o',...
    'MarkerEdgeColor','b','DisplayName','Data')
hold on
plot([-0.45:0.01:0.38],-.000011+.0706729*[-0.45:0.01:0.38],'b','HandleVisibility','off')
xlabel('Exposure to industry shocks (composition of employment)')
ylabel('Exposure to technological waves (composition of patenting)')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Figure 3:
figure
%% 1950:
binscatter_points = csvread('results_model\log_pop_income_model_data_1950.csv',1,0);
subplot(2,2,1), scatter(binscatter_points(:,1),binscatter_points(:,2),'b','o',...
    'MarkerEdgeColor','b','MarkerFaceColor','b','DisplayName','Data')
hold on
subplot(2,2,1), plot(binscatter_points(:,1),-2.110533+.1562992*binscatter_points(:,1),'b','HandleVisibility','off')

subplot(2,2,1), scatter(binscatter_points(:,1),binscatter_points(:,3),'r','d',...
    'MarkerEdgeColor','r','MarkerFaceColor','r','DisplayName','Model')
subplot(2,2,1), plot(binscatter_points(:,1),-1.697926+.1257428*binscatter_points(:,1),'r','HandleVisibility','off')
xlabel('Log-population')
ylabel('Log-income (deviation from mean)')
xlim([min(binscatter_points(:,1)) - 0.2, max(binscatter_points(:,1)) + 0.2])
ylim([min(min(binscatter_points(:,2:3))) - 0.05, max(max(binscatter_points(:,2:3))) + 0.05])

%% 1970:
binscatter_points = csvread('results_model\log_pop_income_model_data_1970.csv',1,0);
subplot(2,2,2), scatter(binscatter_points(:,1),binscatter_points(:,2),'b','o',...
    'MarkerEdgeColor','b','MarkerFaceColor','b','DisplayName','Data')
hold on
subplot(2,2,2), plot(binscatter_points(:,1),-1.39479+.1002017*binscatter_points(:,1),'b','HandleVisibility','off')

subplot(2,2,2), scatter(binscatter_points(:,1),binscatter_points(:,3),'r','d',...
    'MarkerEdgeColor','r','MarkerFaceColor','r','DisplayName','Model')
subplot(2,2,2), plot(binscatter_points(:,1),-1.186971+.085272*binscatter_points(:,1),'r','HandleVisibility','off')
xlabel('Log-population')
ylabel('Log-income (deviation from mean)')
xlim([min(binscatter_points(:,1)) - 0.2, max(binscatter_points(:,1)) + 0.2])
ylim([min(min(binscatter_points(:,2:3))) - 0.05, max(max(binscatter_points(:,2:3))) + 0.05])

%% 1990:
binscatter_points = csvread('results_model\log_pop_income_model_data_1990.csv',1,0);
subplot(2,2,3), scatter(binscatter_points(:,1),binscatter_points(:,2),'b','o',...
    'MarkerEdgeColor','b','MarkerFaceColor','b','DisplayName','Data')
hold on
subplot(2,2,3), plot(binscatter_points(:,1),-1.659871+.1176658*binscatter_points(:,1),'b','HandleVisibility','off')

subplot(2,2,3), scatter(binscatter_points(:,1),binscatter_points(:,3),'r','d',...
    'MarkerEdgeColor','r','MarkerFaceColor','r','DisplayName','Model')
subplot(2,2,3), plot(binscatter_points(:,1),-1.346892+.0954792*binscatter_points(:,1),'r','HandleVisibility','off')
xlabel('Log-population')
ylabel('Log-income (deviation from mean)')
xlim([min(binscatter_points(:,1)) - 0.2, max(binscatter_points(:,1)) + 0.2])
ylim([min(min(binscatter_points(:,2:3))) - 0.05, max(max(binscatter_points(:,2:3))) + 0.05])

%% 2010:
binscatter_points = csvread('results_model\log_pop_income_model_data_2010.csv',1,0);
subplot(2,2,4), scatter(binscatter_points(:,1),binscatter_points(:,2),'b','o',...
    'MarkerEdgeColor','b','MarkerFaceColor','b','DisplayName','Data')
hold on
subplot(2,2,4), plot(binscatter_points(:,1),-1.308275+.0912406*binscatter_points(:,1),'b','HandleVisibility','off')

subplot(2,2,4), scatter(binscatter_points(:,1),binscatter_points(:,3),'r','d',...
    'MarkerEdgeColor','r','MarkerFaceColor','r','DisplayName','Model')
subplot(2,2,4), plot(binscatter_points(:,1),-1.056983+.0737152*binscatter_points(:,1),'r','HandleVisibility','off')
xlabel('Log-population')
ylabel('Log-income (deviation from mean)')
lgd = legend;
xlim([min(binscatter_points(:,1)) - 0.2, max(binscatter_points(:,1)) + 0.2])
ylim([min(min(binscatter_points(:,2:3))) - 0.05, max(max(binscatter_points(:,2:3))) + 0.05])

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Appendix Figure A.9:
figure
%% 1950:
scatter_points = csvread('results_model\log_income_model_data_1950.csv',1,0);
subplot(2,2,1), scatter(scatter_points(:,1),scatter_points(:,2),0.0001*scatter_points(:,3),'b','o',...
    'MarkerEdgeColor','b')
hold on
subplot(2,2,1), plot(scatter_points(:,1),2.59e-10+1.145333*scatter_points(:,1),'r','HandleVisibility','off','LineWidth',1)
xlabel('Log-income per capita (model)')
ylabel('Log-income per capita (data)')
xlim([min(scatter_points(:,1)) - 0.2, max(scatter_points(:,1)) + 0.2])
ylim([min(min(scatter_points(:,2))) - 0.2, max(max(scatter_points(:,2))) + 0.2])

%% 1970:
scatter_points = csvread('results_model\log_income_model_data_1970.csv',1,0);
subplot(2,2,2), scatter(scatter_points(:,1),scatter_points(:,2),0.0001*scatter_points(:,3),'b','o',...
    'MarkerEdgeColor','b')
hold on
subplot(2,2,2), plot(scatter_points(:,1),2.00e-09+.6568693*scatter_points(:,1),'r','HandleVisibility','off','LineWidth',1)
xlabel('Log-income per capita (model)')
ylabel('Log-income per capita (data)')
xlim([min(scatter_points(:,1)) - 0.2, max(scatter_points(:,1)) + 0.2])
ylim([min(min(scatter_points(:,2))) - 0.2, max(max(scatter_points(:,2))) + 0.2])

%% 1990:
scatter_points = csvread('results_model\log_income_model_data_1990.csv',1,0);
subplot(2,2,3), scatter(scatter_points(:,1),scatter_points(:,2),0.0001*scatter_points(:,3),'b','o',...
    'MarkerEdgeColor','b')
hold on
subplot(2,2,3), plot(scatter_points(:,1),8.58e-10+.7450224*scatter_points(:,1),'r','HandleVisibility','off','LineWidth',1)
xlabel('Log-income per capita (model)')
ylabel('Log-income per capita (data)')
xlim([min(scatter_points(:,1)) - 0.2, max(scatter_points(:,1)) + 0.2])
ylim([min(min(scatter_points(:,2))) - 0.2, max(max(scatter_points(:,2))) + 0.2])

%% 2010:
scatter_points = csvread('results_model\log_income_model_data_2010.csv',1,0);
subplot(2,2,4), scatter(scatter_points(:,1),scatter_points(:,2),0.0001*scatter_points(:,3),'b','o',...
    'MarkerEdgeColor','b')
hold on
subplot(2,2,4), plot(scatter_points(:,1),1.17e-09+.668712*scatter_points(:,1),'r','HandleVisibility','off','LineWidth',1)
xlabel('Log-income per capita (model)')
ylabel('Log-income per capita (data)')
xlim([min(scatter_points(:,1)) - 0.2, max(scatter_points(:,1)) + 0.2])
ylim([min(min(scatter_points(:,2))) - 0.2, max(max(scatter_points(:,2))) + 0.2])

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Appendix Figure A.10:
figure
%% 1990:
scatter_points = csvread('results_model\log_income_city_sector_1990.csv',1,0);
subplot(1,2,1), scatter(scatter_points(:,1),scatter_points(:,2),'b','o',...
    'MarkerEdgeColor','b','MarkerFaceColor','b')
hold on
subplot(1,2,1), plot(scatter_points(:,1),9.419854+.3315499*scatter_points(:,1),'r','HandleVisibility','off','LineWidth',1)
xlabel('Log-income per capita (model)')
ylabel('Log-income per capita (data)')
xlim([min(scatter_points(:,1)) - 0.05, max(scatter_points(:,1)) + 0.05])
ylim([min(min(scatter_points(:,2))) - 0.05, max(max(scatter_points(:,2))) + 0.05])

%% 2010:
scatter_points = csvread('results_model\log_income_city_sector_2010.csv',1,0);
subplot(1,2,2), scatter(scatter_points(:,1),scatter_points(:,2),'b','o',...
    'MarkerEdgeColor','b','MarkerFaceColor','b')
hold on
subplot(1,2,2), plot(scatter_points(:,1),9.732466+.4026786*scatter_points(:,1),'r','HandleVisibility','off','LineWidth',1)
xlabel('Log-income per capita (model)')
ylabel('Log-income per capita (data)')
xlim([min(scatter_points(:,1)) - 0.05, max(scatter_points(:,1)) + 0.05])
ylim([min(min(scatter_points(:,2))) - 0.05, max(max(scatter_points(:,2))) + 0.05])

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Appendix Figure A.8:
decades_alphas = [1890:20:2010];
classes_names = ["Agriculture","Domestic articles","Health","Separating","Transporting", ...
    "Chemistry","Construction","Engines","Lighting","Physics","Electricity"]
figure
for s=1:S
    subplot(4,3,s), plot(decades_alphas,alpha_dyn(s,3:end),'Linewidth',1);
    subplot(4,3,s), xlim([1890 2010])
    subplot(4,3,s), ylim([0.7 1.3])
    subplot(4,3,s), xticks([1890,1930,1970,2010])
    subplot(4,3,s), title(classes_names(s))
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

